package com.ruoyi.wxApp.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysDishes;
import com.ruoyi.system.service.ISysHotCuisineDishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜品管理Controller
 * 
 * @author ruoyi
 * @date 2024-09-26
 */
@Anonymous
@RestController
@RequestMapping("/wx/hotCuisineDishes")
public class WxHotCuisineDishesController extends BaseController
{
    @Autowired
    private ISysHotCuisineDishesService sysHotCuisineDishesService;

    /**
     * 查询菜品管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDishes sysColdDishes)
    {
        startPage();
        List<SysDishes> list = sysHotCuisineDishesService.selectSysDishesList(sysColdDishes);
        return getDataTable(list);
    }

    /**
     * 导出菜品管理列表
     */
    @Log(title = "菜品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDishes sysColdDishes)
    {
        List<SysDishes> list = sysHotCuisineDishesService.selectSysDishesList(sysColdDishes);
        ExcelUtil<SysDishes> util = new ExcelUtil<SysDishes>(SysDishes.class);
        util.exportExcel(response, list, "菜品管理数据");
    }

    /**
     * 获取菜品管理详细信息
     */
    @GetMapping(value = "/{dishesId}")
    public AjaxResult getInfo(@PathVariable("dishesId") Long dishesId)
    {
        return success(sysHotCuisineDishesService.selectSysDishesByDishesId(dishesId));
    }

    /**
     * 新增菜品管理
     */
    @Log(title = "菜品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDishes sysColdDishes)
    {
        return toAjax(sysHotCuisineDishesService.insertSysDishes(sysColdDishes));
    }

    /**
     * 修改菜品管理
     */
    @Log(title = "菜品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDishes sysColdDishes)
    {
        return toAjax(sysHotCuisineDishesService.updateSysDishes(sysColdDishes));
    }

    /**
     * 删除菜品管理
     */
    @Log(title = "菜品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dishesIds}")
    public AjaxResult remove(@PathVariable Long[] dishesIds)
    {
        return toAjax(sysHotCuisineDishesService.deleteSysDishesByDishesIds(dishesIds));
    }

    /**
     * 修改状态
     */
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysDishes sysColdDishes)
    {
        System.out.println(sysColdDishes);
        return toAjax(sysHotCuisineDishesService.updateSysSysDishes(sysColdDishes));
    }

    /**
     * 修改购物车
     */
/*    @PreAuthorize("@ss.hasPermi('system:dishes:edit')")
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/shoppingChange")
    public AjaxResult shoppingChange(@RequestBody SysDishes sysColdDishes)
    {
        SysDishes sysDishess = new SysDishes();
        sysDishess.setDishesId(sysColdDishes.getDishesId());
        System.out.println(sysColdDishes);
        if (sysColdDishes.getShoppingChange() >=1){
            sysDishess.setPackageId("1");
            sysHotMealDishesService.updateSysDishes(sysDishess);
        }else {
            sysDishess.setPackageId("0");
            sysHotMealDishesService.updateSysDishes(sysDishess);
        }
        return toAjax(sysHotMealDishesService.updateSysDishes(sysColdDishes));
    }*/
}
